import threading
import time


def run(i):
    print('子线程开始', threading.current_thread().name)
    print(f'{i}开始干活')
    time.sleep(3)
    print(f'{i}完成干活')

if __name__ == '__main__':
    t1 = time.time()

    # 错误使用，实际上就是一个一个在执行
    # for i in range(1, 6):
    #     thr = threading.Thread(target=run, args=(i,))
    #     thr.start()
    #     thr.join()
    # print('over')
    # print(time.time()-t1)

    # 正确方法
    t_list = []
    for i in range(1, 6):
        thr = threading.Thread(target=run, args=(i, ))
        # 将线程对象添加到列表
        t_list.append(thr)
    # 循环开启子线程
    for t in t_list:
        t.start()
    # 循环阻塞子线程
    for j in t_list:
        j.join()
    print('over')
    print(time.time()-t1)
